//
//  UIButton+Extension.swift
//  Weibo_SwiftDemo
//
//  Created by gjh on 2020/12/23.
//

import UIKit

extension UIBarButtonItem {
    
    /// 初始化 button
    /// - Parameters:
    ///   - title: 标题
    ///   - titleColor: 标题颜色
    ///   - highlightColor: 高亮颜色
    ///   - target: 目标
    ///   - action: 点击方法
    convenience init(title: String, titleColor: UIColor?, highlightColor: UIColor?, target: Any?, action: Selector, isback: Bool = false) {
        
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(titleColor, for: .normal)
        btn.setTitleColor(highlightColor, for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        btn.addTarget(target, action: action, for: .touchUpInside)
        if isback {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        }
        
        self.init(customView: btn)
    }
}
